import Vue from 'vue'
import VueRouter from 'vue-router'
import Permission from '@/views/Permission.vue'
import Home from '@/views/Home.vue'
import Role from '@/views/Role.vue'
import User from '@/views/User.vue'
import DistributePermissionToRole from '@/views/DistributePermissionToRole.vue'
import DistRoleToEmp from '@/views/DistRoleToEmp.vue'
import Login from '@/views/Login.vue'
import Comment from '@/views/Comment.vue'
import Log from '@/views/Log.vue'
import AllUser from '@/views/AllUser.vue'
import Indent from '@/views/Indent.vue'
import Dept from '@/views/Dept.vue'
import Hospital from '@/views/Hospital.vue'
import Bed from '@/views/Bed.vue'
import SaleStatement from '@/views/SaleStatement.vue'
import AllStatement from '@/views/AllStatement.vue'
import Fault from '@/views/Fault.vue'
import Fix from '@/views/Fix.vue'
import Repairman from '@/views/Repairman.vue'
import Accounting from '@/views/Accounting.vue'
import Admin from '@/views/Admin.vue'
import HospitalAdmin from '@/views/HospitalAdmin.vue'
import Shareholder from '@/views/Shareholder.vue'
import Sickroom from '@/views/Sickroom.vue'
import demo from "@/views/demo.vue";
import demo02 from "@/views/demo02.vue";
import Personal from "@/views/Personal.vue";
import ChangePassword from "@/views/ChangePassword.vue";
import Emp from "@/views/Emp.vue";


Vue.use(VueRouter)

const routes = [
    {
        path: "/Login",
        component: Login
    }, {
        path: "/dem02",
        component: demo02
    }, {
        path: "/demo",
        component: demo
    },
    {
        path: "/",
        component: Home,
        meta: {
            title: "首页"
        },
        redirect:'/User',
        children: [
            {
                meta: {
                    title: "权限管理"
                },
                path: "/Permission",
                component: Permission
            },
            {
                meta: {
                    title: "用户管理"
                },
                path: "/User",
                component: User
            },
            {
                meta: {
                    title: "角色管理"
                },
                path: "/Role",
                component: Role
            },
            {
                meta: {
                    title: "分配权限"
                },
                path: "/DistributePermissionToRole/:roleId",
                component: DistributePermissionToRole
            },
            {
                path: "/DistRoleToEmp/:empId",
                component: DistRoleToEmp
            },
            {
                meta: {
                    title: "用户反馈"
                },
                path: "/Comment",
                component: Comment
            },
            {
                meta: {
                    title: "操作日志"
                },
                path: "/Log",
                component: Log
            },
            {
                meta: {
                    title: "用户列表"
                },
                path: "/AllUser",
                component: AllUser
            },
            {
                meta: {
                    title: "订单管理"
                },
                path: "/Indent",
                component: Indent
            },
            {
                meta: {
                    title: "科室管理"
                },
                path: "/Dept",
                component: Dept
            },
            {
                meta: {
                    title: "医院管理"
                },
                path: "/Hospital",
                component: Hospital
            },
            {
                meta: {
                    title: "床位列表"
                },
                path: "/Bed",
                component: Bed
            },
            {
                meta: {
                    title: "销售报表"
                },
                path: "/SaleStatement",
                component: SaleStatement
            },
            {
                meta: {
                    title: "报表概况"
                },
                path: "/AllStatement",
                component: AllStatement
            },
            {
                meta: {
                    title: "维修记录"
                },
                path: "/Fix",
                component: Fix
            },
            {
                meta: {
                    title: "故障列表"
                },
                path: "/Fault",
                component: Fault
            },
            {
                path: "/Repairman",
                component: Repairman
            },
            {
                path: "/Accounting",
                component: Accounting
            },
            {
                path: "/Admin",
                component: Admin
            },
            {
                meta: {
                    title: "股东/分销商"
                },
                path: "/Shareholder",
                component: Shareholder
            },
            {
                meta: {
                    title: "医院管理员"
                },
                path: "/HospitalAdmin",
                component: HospitalAdmin
            },
            {
                meta: {
                    title: "病房管理"
                },
                path: "/Sickroom",
                component: Sickroom
            },
            {
                meta: {
                    title: "个人中心"
                },
                path: "/Personal",
                component: Personal
            },
            {
                meta: {
                    title: "修改密码"
                },
                path: "/ChangePassword",
                component: ChangePassword
            },
            {
                meta: {
                    title: "后台用户管理"
                },
                path: "/Emp",
                component: Emp
            }
        ]
    }

]

const router = new VueRouter({
    routes
})

let whiteList = ['/Login']; // 不重定向白名单

router.beforeEach((to, from, next) => {
    if (whiteList.includes(to.path)) {
        next();
        return;
    }

    let loginEmp = sessionStorage.getItem("loginEmp");
    if (!loginEmp) {
        router.push("/Login");
        return;
    }
    next();
})

export default router
